package com.cssl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cssl.pojo.Location;
import com.cssl.service.LocationService;
import com.cssl.vo.LocationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LocationController {

    @Autowired
    private LocationService lservice;

    @PostMapping("/pagelocation")
    public LocationVo pagepublished(Integer current, Integer size){
        if (current==null||current<1){
            current=1;
        }
        if(size==null||size<1){
            size=3;
        }
        LocationVo locationVo = new LocationVo();
        IPage<Location> page=new Page<>(current,size);
        lservice.page(page,null);
        locationVo.setCurrent(current);
        locationVo.setSize(size);
        locationVo.setTotal(page.getTotal());
        locationVo.setUserList(page.getRecords());
        locationVo.setCount(page.getPages());
        return locationVo;
    }

    //添加
    @PostMapping("/addloca")
    public boolean addloca(Location lt){
        return lservice.save(lt);
    }

    //按id查询
    @PostMapping("/sellid")
    public Location sellid(Integer lid){
        return lservice.getBaseMapper().selectById(lid);
    }

    //按id修改
    @PostMapping("/updlid")
    public boolean updlid(Location lt){
        return lservice.updateById(lt);
    }

    //按id删除
    @PostMapping("/dellid")
    public int dellid(Integer lid){
        return lservice.getBaseMapper().deleteById(lid);
    }

    @PostMapping("/selwei")
    public Location selwei(int lid){
        return  lservice.selwei(lid);
    }

    @PostMapping("/licationall")
    public List<Location> locationall(){
        return lservice.list();
    }
}
